package com.json.controller;

import com.alibaba.fastjson2.JSON;
import com.json.service.StudentService;
import com.json.service.impl.StudentServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/delete")
public class StudentDelete extends HttpServlet {
    @Override
    protected void doDelete(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Integer id = Integer.parseInt(req.getParameter("id"));
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
        resp.setContentType("application/json;charset=utf-8");
        StudentService studentService = new StudentServiceImpl();
        if (studentService.remove(id)){
            resp.getWriter().write(JSON.toJSONString("删除成功"));
        }
        else {
            resp.getWriter().write(JSON.toJSONString("删除失败"));
        }


    }
}
